***Curtis RESTAT
***This do-file runs the regressions found in table A1
**Change to directory where data and code were downloaded
**cd 

set matsize 1500
clear all
set more off

use cbp_st_tableA1,clear

drop if enint==0 /*keeps only MFTG Industries*/
drop if fipstate=="11" /*Drops DC*/

do dataclean_tableA1.do

gen empweight2=emp if year==1998
bysort stateind:carryforward empweight2,replace

so stateind year
egen empweight3t=mean(emp),by(stateind post)
replace empweight3t=. if post==1
egen empweight3=max(empweight3t),by(stateind)

gen NBPstr="NBP" if NBP==1
replace NBPstr="west" if NBPstr==""
gen NBPind=NBPstr+naics

drop yeardum*
tab year,gen(yeardum)

gen trend=year-1997
qui tab fipstate,gen(STdum)
foreach var of varlist ind1-ind21 {
	qui gen trend`var'=`var'*trend
}

foreach x of varlist STdum1-STdum49 {
	qui gen trend`x'=`x'*trend
}

/* Generate Seperate NBP/West Trends by Industry*/
forvalues i = 1(1)21 {
  qui gen eindtrend`i' = trendind`i'*NBP
 }
forvalues i = 1(1)21 {
  qui gen windtrend`i' = trendind`i'*((NBP-1)^2)
 }
tostring NBP,replace
gen yearindreg=yearind+"_"+NBP


qui tab yearind,gen(yearinddum)
qui tab STyear, gen(STyeardum)
qui tab stateind, gen(stateinddum)

/* Defines RHS variables to be included in every regression*/
mac def rhs_vars "postxint intxNBP postxNBP  "
save ddbase_tableA1,replace

*Keeps only states in the NBP region
drop if NBP=="0"
*Column 1
qui eststo:areg lemp postxint yeardum* eindtrend* [aweight=empweight2],abs(stateind) rob cluster(NBPind)
*Column 2
qui eststo:areg lemp postxint STyeardum* eindtrend* [aweight=empweight2],abs(stateind) rob cluster(NBPind)

outreg2 [est1 est2] using "tableA1a.tex",keep(postxint) nocons replace
eststo clear


use ddbase,clear
***Uses all US states but keeps only high energy industries
drop if enint<.025
*Column 3
qui eststo:areg lemp postxNBP yeardum* eindtrend* [aweight=empweight2],abs(stateind) rob cluster(stateind)
*Column 4
qui eststo:areg lemp postxNBP yearinddum* eindtrend* [aweight=empweight2],abs(stateind) rob cluster(stateind)
**Note that Column 5 is taken direct from Table 2 Panel A column 6
outreg2 [est1 est2] using "../tableA1b.tex",keep(postxNBP postxNBPxint) nocons append

